<template>
  <el-form label-width="100" :model="loginForm">
    <el-form-item label="用户名" prop="userName">
      <el-input v-model="loginForm.userName"></el-input>
    </el-form-item>
    <el-form-item label="password" prop="password">
      <el-input type="password" v-model="loginForm.password"></el-input>
    </el-form-item>
    <el-form-item label="验证码" prop="captcha">
      <el-input type="captcha" v-model="loginForm.captcha"></el-input>
    </el-form-item>
    <span v-html="svg"></span>
    <el-form-item>
      <el-button @click="doLogin">登录</el-button>
    </el-form-item>
  </el-form>
</template>
<script lang="ts" setup>
import { GET_CHECK_CODE,DO_LOGIN, ILogin } from '@/api/login';
import { ref } from 'vue';
const svg = ref()
const loginForm = ref({
  userName: '',
  password: '',
  captcha: ''
})

const getCheckCode = () => {
  GET_CHECK_CODE().then(res => {
    svg.value = res.data
  })
}
const doLogin = () => {
  let params:ILogin = {
    username: loginForm.value.userName,
    password: loginForm.value.password,
    captcha: loginForm.value.captcha
  }
  DO_LOGIN(params).then(res => {
    console.log(res)
    localStorage.setItem('aaa', res.data.token)
  })
}
getCheckCode()
</script>